//
//  AddressDao.m
//  shop
//
//  Created by jiangshao on 17/6/1.
//  Copyright © 2017年 geek-zoo studio. All rights reserved.
//

#import "AddressDao.h"
#import "SVProgressHUD.h"
#import "Bee_Precompile.h"
#import "Bee_Foundation.h"
#import "Bee_Message.h"

//#import "AFHTTPSessionManager.h"

@implementation AddressDao


-(void)get_pickup_point{
    NSString *url=@"http://md.xlinweb.com/api.php";
    NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
    [dict setObject:@"get_pickup_point" forKey:@"act"];
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    session.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [session POST:url parameters:dict success:^(NSURLSessionDataTask *task, id responseObject) {
        NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
        [dict setObject:responseObject forKey:@"get_pickup_point"];
        [self.remoteDaoDelegate getRemotedata:dict];
        NSLog(@"成功");
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"接口请求失败"];;
    }];
}


-(void)get_my_address{
    NSString *url=@"http://md.xlinweb.com/api.php";
    NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
    [dict setObject:@"get_my_address" forKey:@"act"];
    BeeMessage *message=[BeeMessage message];
    SESSION * msgsession = message.GET_INPUT( @"session" );
    [dict setObject:msgsession.uid forKey:@"userid"];
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    session.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [session POST:url parameters:dict success:^(NSURLSessionDataTask *task, id responseObject) {
        [SVProgressHUD dismiss];
        NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
        [dict setObject:responseObject forKey:@"get_my_address"];
        [self.remoteDaoDelegate getRemotedata:dict];
        NSLog(@"成功");
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"接口请求失败"];;
    }];
}


-(void)add_my_address:(NSInteger)pointid tel:(NSString *)tel{
    [SVProgressHUD showWithStatus:@""];

    NSString *url=@"http://md.xlinweb.com/api.php";
    NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
    [dict setObject:@"add_my_address" forKey:@"act"];
    BeeMessage *message=[BeeMessage message];
    SESSION * msgsession = message.GET_INPUT( @"session" );
    [dict setObject:msgsession.uid forKey:@"userid"];
     [dict setObject:[NSNumber numberWithInteger:pointid ] forKey:@"pointid"];
     [dict setObject:tel forKey:@"tel"];
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    session.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [session POST:url parameters:dict success:^(NSURLSessionDataTask *task, id responseObject) {
        [SVProgressHUD dismiss];
        NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
        [dict setObject:responseObject forKey:@"add_my_address"];
        [self.remoteDaoDelegate getRemotedata:dict];
        NSLog(@"成功");
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"接口请求失败"];;
    }];
}



-(void)edit_my_address:(NSInteger)pointid tel:(NSString *)tel address_id:(NSInteger)address_id{
    [SVProgressHUD showWithStatus:@""];
    NSString *url=@"http://md.xlinweb.com/api.php";
    NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
    [dict setObject:@"edit_my_address" forKey:@"act"];
    BeeMessage *message=[BeeMessage message];
    SESSION * msgsession = message.GET_INPUT( @"session" );
    [dict setObject:msgsession.uid forKey:@"userid"];
    [dict setObject:[NSNumber numberWithInteger:pointid ] forKey:@"pointid"];
    [dict setObject:tel forKey:@"tel"];
    [dict setObject:[NSNumber numberWithInteger:address_id ] forKey:@"address_id"];
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    session.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [session POST:url parameters:dict success:^(NSURLSessionDataTask *task, id responseObject) {
        [SVProgressHUD dismiss];
        NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
        [dict setObject:[NSNumber numberWithInteger:address_id] forKey:@"edit_my_address"];
        [self.remoteDaoDelegate getRemotedata:dict];
        NSLog(@"成功");
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"接口请求失败"];;
    }];
}

-(void)del_my_address:(NSInteger)address_id{
    [SVProgressHUD showWithStatus:@""];
    NSString *url=@"http://md.xlinweb.com/api.php";
    NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
    [dict setObject:@"del_my_address" forKey:@"act"];
    BeeMessage *message=[BeeMessage message];
    SESSION * msgsession = message.GET_INPUT( @"session" );
    [dict setObject:msgsession.uid forKey:@"userid"];
    [dict setObject:[NSNumber numberWithInteger:address_id ] forKey:@"address_id"];
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    session.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [session POST:url parameters:dict success:^(NSURLSessionDataTask *task, id responseObject) {
        [SVProgressHUD dismiss];
        NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
        [dict setObject:[NSNumber numberWithInteger:address_id] forKey:@"del_my_address"];
        [self.remoteDaoDelegate getRemotedata:dict];
        NSLog(@"成功");
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"接口请求失败"];;
    }];
}


-(void)set_default_addr:(NSInteger)address_id{
    [SVProgressHUD showWithStatus:@""];
    NSString *url=@"http://md.xlinweb.com/api.php";
    NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
    [dict setObject:@"set_default_addr" forKey:@"act"];
    BeeMessage *message=[BeeMessage message];
    SESSION * msgsession = message.GET_INPUT( @"session" );
    [dict setObject:msgsession.uid forKey:@"userid"];
    [dict setObject:[NSNumber numberWithInteger:address_id ] forKey:@"address_id"];
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    session.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [session POST:url parameters:dict success:^(NSURLSessionDataTask *task, id responseObject) {
        [SVProgressHUD dismiss];
        NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
        [dict setObject:responseObject forKey:@"set_default_addr"];
        [self.remoteDaoDelegate getRemotedata:dict];
        NSLog(@"成功");
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"接口请求失败"];;
    }];
}




@end
